package com.kotlin.android.core

import android.app.Application
import android.content.Context
import com.alibaba.android.arouter.launcher.ARouter
import com.kotlin.android.core.ext.versionName
import com.kotlin.android.ktx.utils.LogUtils
import kotlin.properties.Delegates

/**
 *
 * Created on 2020/4/21.
 *
 * @author o.s
 */
open class CoreApp : Application() {

    companion object {
        var instance: Context by Delegates.notNull()
    }

    override fun onCreate() {
        super.onCreate()
        initRouter()
        instance = applicationContext
        initLogManager()
    }

    /**
     * 初始化isDebug开关配置
     */
    private fun initLogManager() {
        LogUtils.isDebug = BuildConfig.DEBUG
        when (BuildConfig.DEBUG) {
            true -> {
                LogUtils.init(versionName)
            }
        }
    }

    /**
     * 初始化路由组件
     */
    private fun initRouter() {
        if (BuildConfig.DEBUG) {
            ARouter.openLog()
            ARouter.openDebug()
        }
        ARouter.init(this)
    }

}